<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<div id="candidate" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    <?=$this->lang->line("Data Entry")?> > <?=$this->lang->line("Order")?>
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24"><?=$this->lang->line("TodayIS")?> <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="detail-menu">
        <?php if($type==0){?>
            <div class="active1 detail-active menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 single-menu menu" id="menu2"><?=$this->lang->line("InProfile")?></div>
            <div class="active3 single-menu menu" id="menu3"><?=$this->lang->line("Archived")?></div>
        <?php }else if($type==1){?>
            <div class="active1 single-menu menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 detail-active menu" id="menu2"><?=$this->lang->line("InProfile")?></div>
            <div class="active3 single-menu menu" id="menu3"><?=$this->lang->line("Archived")?></div>
        <?php }else if($type==4){?>
            <div class="active1 single-menu menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 single-menu menu" id="menu2"><?=$this->lang->line("InProfile")?></div>
            <div class="active3 detail-active menu" id="menu3"><?=$this->lang->line("Archived")?></div>
        <?php }?>
        <div style="width:0px;"></div>
    </div>
    <div class="list-div" style="margin-top:0px;">
        <?php echo form_open('profile/order'); ?>
        <table class="top-table">
            <tr>
                <td>
                    <input type="hidden" value="<?=$ordername?>" name="ordername" id="ordername" />
                    <input type="hidden" value="<?=$type?>" name="type" />
                </td>
                <td width="240" class="center"><input type="text" placeholder="<?=$this->lang->line("searchmsg")?>" 
                    name="condition" value="<?=$condition?>"/></td>
                <td width="90" class="center"><input type="submit" value="<?=$this->lang->line("Search")?>" /></td>
                <td width="110" class="center"><input type="button" value="<?=$this->lang->line("New")?>" id="new"/></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table class="list-table">
            <tr>
                <th width="60" class="order" ordername="o.sn"><?=$this->lang->line("SN")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="o.position"><?=$this->lang->line("Position")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="o.priority"><?=$this->lang->line("Priority")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="c.name"><?=$this->lang->line("CompanyName")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="e.username"><?=$this->lang->line("Salesman")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="o.salary"><?=$this->lang->line("Salary")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="70" class="order" ordername="o.gender"><?=$this->lang->line("Gender")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="o.worktype"><?=$this->lang->line("WorkType")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <?php if($this->session->userdata('department') == 1){?>
                <th width="60"></th>
                <?php if($type==0){?>
                <th width="60"></th>
                <th width="60"></th>
                <?php }else if($type==1){?>
                <th width="60"></th>  
                <?php }else if($type==4){?>
                <th width="60"></th>    
                <?php }}?>
            </tr>
            <?php foreach ($order as $key => $value) {?>
            <tr>
                <td><?=$value['sn']?></td>
                <td><?=$value['position']?></td>
                <td><?=$value['priority']==1?"A":($value['priority']==2?"B":($value['priority']==3?"C":"Other"))?></td>
                <td><?=$value['companyname']?></td>
                <td><?=$value['salesman']?></td>
                <td><?=$value['salary']?></td>
                <td><?=$value['gender']==1?"M":($value['gender']==2?"F":"M or F")?></td>
                <td><?=$value['worktype']==1?"WP":($value['worktype']==2?"SP":($value['worktype']==3?"EP":"Other"))?></td>
                <!--<td><a href="javascript:void(0)" class="buttona profile" candidateid="<?=$value['id']?>" workernum="<?=$value['workernum']?>"><img src="<?=base_url()?>resource/img/rightarr.png"/>Submit</a></td>-->
                <?php if($this->session->userdata('department') == 1){?>
                <td><a href="javascript:void(0)" class="buttona detail" candidateid="<?=$value['id']?>"><img src="<?=base_url()?>resource/img/detail.png"/><?=$this->lang->line("Edit")?></a></td>
                <?php if($type==0){?>
                <td><a href="javascript:void(0)" class="buttona delete" candidateid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/delete.png"/><?=$this->lang->line("Delete")?></a></td>
                <td>
                    <a href="javascript:void(0)" class="buttona archived" profileid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/archived.png"/><?=$this->lang->line("Archived")?>
                    </a>
                </td>
                <?php }else if($type == 1){?>
                <td><a href="javascript:void(0)" class="buttona restore" profileid="<?=$value['id']?>">
                            <img src="<?=base_url()?>resource/img/restore.png"/><?=$this->lang->line("Restore")?>
                        </a>
                </td>
                <?php }else if($type == 4){?>
                <td>
                    <a href="javascript:void(0)" class="buttona restore" profileid="<?=$value['id']?>">
                            <img src="<?=base_url()?>resource/img/restore.png"/><?=$this->lang->line("Restore")?>
                        </a>
                </td>
                <?php }}?>
            </tr>
            <?php }
            if(count($order) == 0){?>
            <tr>
                <td colspan="9">
                    NO DATA
                </td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="9" class="pagination">
                    <?php echo $page;?>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
$(".menu").click(function(){
    var id = $(this).attr("id");
    var url = "<?=base_url()?>profile/order";
    if(id == "menu1"){
        url += "?type=0";
    }else if(id == "menu2"){
        url += "?type=1";
    }else if(id == "menu3"){
        url += "?type=4";
    }
    location.href = url;
});    

$(".detail").click(function(){
    var id = $(this).attr("candidateid");
    var url = '<?=base_url()?>profile/order_detail/'+id;
    location.href=url;
});

$(".delete").click(function(){
    if(confirm("Are you sure delete this order?")){
        var id = $(this).attr("candidateid");
        var url = '<?=base_url()?>profile/deleteorder?id='+id;
        location.href=url;
    }
});

$("#new").click(function(){
    var url = '<?=base_url()?>profile/new_order';
    location.href=url;
});

$(".profile").click(function(){
    var id = $(this).attr("candidateid");
    var workernum = $(this).attr("workernum");
    if(workernum > 0){
        var iTop = (document.body.clientHeight-30-600)/2; //获得窗口的垂直位置;
        var iLeft = (document.body.clientWidth-10-800)/2; //获得窗口的水平位置;
        window.open('<?=base_url("profile/submit_confirmation_letter")?>/'+id,'_blank',
        'width=800,height=600,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,top='+iTop+',left='+iLeft); 
    }else{
        alert("Please add candidate for this order.");
    }
});

var url = '<?=base_url()?>profile/order';
var order = "<?=$ordername?>";
var orders = order.split(" ");
$("th").each(function(){
    var ordername = $(this).attr("ordername");
    if(orders[0] == ordername){
        $(this).children("img").attr("src","<?=base_url()?>resource/img/arrow_"+orders[1]+".png");
    }
});

$(".archived").click(function(){
    var profileid = $(this).attr("profileid");
    location.href = "<?=base_url()?>profile/archived?id="+profileid+"&type=2";
});

$(".restore").click(function(){
    var profileid = $(this).attr("profileid");
    location.href = "<?=base_url()?>profile/restore?id="+profileid+"&type=2";
});
</script>
